﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Threading;
using System.Collections.Specialized;
using DirectoryViewModels;
using System.Threading;
using BrainTechLLC.FileMaintenance;
using BrainTechLLC.WPF;
using DragDropLibrary;

using System.ComponentModel;
using BrainTechLLC.ThreadSafeObjects;
using System.Diagnostics;

namespace BrainTechLLC.FolderExplorer
{
    public partial class FolderExplorerControl : UserControl
    {
        protected bool _needsRecalcVisible;
        private bool _loading;
        protected List<Grid> AllGrids = new List<Grid>();
        private List<Grid> AddedNew = new List<Grid>();

        private void gridTVI_Loaded(object sender, RoutedEventArgs e)
        {
            _loading = true;
            AltGrid g = sender as AltGrid;
            AllGrids.Add(g);
            AddedNew.Add(g);
            FolderViewModel f = g.Tag as FolderViewModel;
            TreeViewItem tvi = g.FindParent<TreeViewItem>();
            g.Folder = f;
            int idx = FindIndex(f.Parent);
            if (idx >= 0)
            {
                if (f.Parent._temp == 0)
                {
                    f.Parent._temp = idx + 1;
                }
                else
                {
                    f.Parent._temp++;
                }
                _TreeViewItems.Insert(f.Parent._temp, tvi);
            }
            else
            {
                _TreeViewItems.Add(tvi);
            }

            if (f != null)
            {
                f._uiContainer = g;

                if (f.IsSelected)
                {
                    g.BringIntoView();
                }
            }            
        }


        private void treeView1_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            _needsRecalcVisible = true;
        }
    }
}
